Script to spell check on a column

Does anyone know of a script to perform a spell check on a specific column?

 

For example, my company uses one column for data entry, and I would like to create a script to run spell check on this column when the test is completed on a module, in which the user is responsible for entering text into this column.

The goal here is to find and then fix any typos that are found before the module is turned in for review.

 

Thank you for any suggestions.


Gedinfo - Sun Sep 07 15:44:10 EDT 2014

Re: Script to spell check on a column
Wolfgang Uhr - Mon Sep 08 02:59:12 EDT 2014

Hi

The dxl-manual contails 26 pages on how to handle the dxl spell checker. Your question should be more detailed.

Best regards

Wolfgang

Re: Script to spell check on a column
llandale - Mon Sep 08 12:52:33 EDT 2014

Never run Spell Checker nor coded it, but I'm sure you when you say "Column" you mean "Attribute.

Looking at the Spelling chapter for the 1st time ever, pehaps this structure works

  • string NameAttr = "Object Text", ErrMess
  • int Start, End
  • for o in m do
  • {  Start = 0
  •     End = 0
  •     ErrMess = spell(o, NameAttr, Start, End)
  •     if (!null ErrMess) then something structurally wrong
  •     elseif (End > 0) then spelling mistake between Start and End inclusive.  What to do now?
  •     else this obj.attr has no spelling mistakes
  • }

-Louie

Re: Script to spell check on a column
Chris Annal - Mon Sep 08 17:02:21 EDT 2014

I don't know if you're aware, but DOORS already has a built-in Spell checker. Open any DOORS module and right-click with your mouse on the top menu in that module. A pop-up checklist will appear that allows you to choose additional tools to add to the menu. One of those tools is "Spelling", which is the DOORS spell-checker. A lot of folks don't know this exists because it isn't put on the menu by default...you have to "Add" it in this fashion. There are a number of other tools you can add from the checklist, too!!

Hmmm. This tool only lists "Object Heading" and "Object Text" as the attributes it will review. Perhaps you can edit the DXL that it uses and modify it for your own use, if neither of these contain the data you're talking about....

Good Luck!

Re: Script to spell check on a column
Wolfgang Uhr - Tue Sep 09 10:44:18 EDT 2014

Chris Annal - Mon Sep 08 17:02:21 EDT 2014

I don't know if you're aware, but DOORS already has a built-in Spell checker. Open any DOORS module and right-click with your mouse on the top menu in that module. A pop-up checklist will appear that allows you to choose additional tools to add to the menu. One of those tools is "Spelling", which is the DOORS spell-checker. A lot of folks don't know this exists because it isn't put on the menu by default...you have to "Add" it in this fashion. There are a number of other tools you can add from the checklist, too!!

Hmmm. This tool only lists "Object Heading" and "Object Text" as the attributes it will review. Perhaps you can edit the DXL that it uses and modify it for your own use, if neither of these contain the data you're talking about....

Good Luck!

Hi

> Hmmm. This tool only lists "Object Heading" and "Object Text" as the attributes it will review.

Create a new attribute and then you can see that it will be listet too.

But I think that the automatic spell check isn't the topic of this question.

Best regards

Wolfgang

Re: Script to spell check on a column
Gedinfo - Tue Sep 09 17:29:09 EDT 2014

Wolfgang Uhr - Tue Sep 09 10:44:18 EDT 2014

Hi

> Hmmm. This tool only lists "Object Heading" and "Object Text" as the attributes it will review.

Create a new attribute and then you can see that it will be listet too.

But I think that the automatic spell check isn't the topic of this question.

Best regards

Wolfgang

I am aware of the built in spell checker(Ctrl+ K).  I have managed to put together a working spell checker for a module or multiple modules in a directory, using the code in the help file. The output is put into a file.

One exception, is that I had to limit the while loop (page 823 of DOORS 9.4 help manual) to exit if spell does not find any issues.

Now, I wish to be able to use the client dictionary to add in certain terms that are common to the industry.

I do see some perms relating to dictionary usage(insert(), open(), etc) that I will allow me to create a script to go through the results of the file and if these terms are found in the file, add them to the dictionary.

If anyone has any experience with this, please feel free to share how you handle these types of situations.

 

Thank you.

Re: Script to spell check on a column
mcnairk - Wed Sep 10 10:04:29 EDT 2014

Gedinfo - Tue Sep 09 17:29:09 EDT 2014

I am aware of the built in spell checker(Ctrl+ K).  I have managed to put together a working spell checker for a module or multiple modules in a directory, using the code in the help file. The output is put into a file.

One exception, is that I had to limit the while loop (page 823 of DOORS 9.4 help manual) to exit if spell does not find any issues.

Now, I wish to be able to use the client dictionary to add in certain terms that are common to the industry.

I do see some perms relating to dictionary usage(insert(), open(), etc) that I will allow me to create a script to go through the results of the file and if these terms are found in the file, add them to the dictionary.

If anyone has any experience with this, please feel free to share how you handle these types of situations.

 

Thank you.

Mark,

Would you be able to share the code for this?

Thanks,

                Ken.

Re: Script to spell check on a column
Gedinfo - Wed Sep 10 14:53:09 EDT 2014

Stream g_stOutput
string OutputFile = "U:\\DoorsLog\\SpellCheck.txt" // Results of this script appear in this file
bool bSingleModule
bool bPrintDVP
string strModuleName
string strNewLine = "\n"
string strBlank = ""
string strSpace = " "
int LOGO_WIDTH = 400
int LOGO_HEIGHT = 95
string SFFType[] =  {"Single File", "Folder"}
string strSelectFileOrFolder = "Select Single File or Folder: "
string strFolderPath = "Folder Path:"
string BITMAP = "U:\\Temp\\file_bmp.bmp"    // This is actually located C:\Temp but the drive is mapped to U
bool g_bDeleteFileValid
string strDoorsOutput = "U:\\DoorsLog"
string strOk = "OK"


//Draws a bitmap - for canvases that displays an image
void repaint(DBE c) { bitmap(c, BITMAP, 0, 0)}


/******************************************************************************
  CompleteMessage

  Displays an Operation Complete message alerting the user where to find the resultant file
******************************************************************************/
void CompleteMessage(string strLogFile)
{
        string strMessage
        string strMap = " where U:\\ is mapped to the 'Client' drive"
        string strComplete = "Operation Complete!!! Output file can be viewed at "
        strMessage = strComplete strLogFile strMap
        infoBox strMessage
} // CompleteMessage()

bool DeleteExistingFile(string strFileToDelete)
{
    string strRetStatus = deleteFile(strFileToDelete)  // needed for 9.4
    if (strRetStatus == null)
    {
            g_bDeleteFileValid = true
    } // end if (RetStatus == null)
    else
    {
            g_bDeleteFileValid = false
            ack "Please close " strFileToDelete " then rerun this script!"
    } // end else
    return(g_bDeleteFileValid)
}  //DeleteExistingFile()


/******************************************************************************
  fDirectory()

  Create a directory if it does not exist
******************************************************************************/
void fDirectory()
{
        bool bDirExists = false
        Stat s
        s = create strDoorsOutput
        if (!null s && directory s)
                bDirExists = true
        if (bDirExists == false)
                mkdir(strDoorsOutput, strBlank)
} //fDirectory()

void PrintModuleName()
{
    if (bPrintDVP)
        {
                // Only print the module name once
                if (!bSingleModule)
                        g_stOutput << strNewLine "**************New DVP**************" strNewLine
                g_stOutput << strModuleName strNewLine
                bPrintDVP = false
        } // end if (bPrintDVP)
} // PrintModuleName()

void Action(string strFullName)
{
        bPrintDVP = true
        string strBase_ID = strBlank
        int iStart = 0
        int iFinish = 0
        int iLength = 0
        string sRetString = strBlank
        Object o
        Module m
        bool bInitial = true
        bool bValidModule = true
        bool bExecutableModule

        if (bSingleModule)
        {
                m = current
        } // end if (bSingleModule)
        else
        {
                m = read(strFullName, false)
                if (m == null)
                        bValidModule = false
        } // end else

        if (bValidModule)
        {
                strModuleName = m."Name"
                for o in m do
                {
                        // check status
                        // -----------------------------------------------------------------------
                        if (o != null)
                        {
                        strBase_ID = identifier(o)
                                iStart = 0
                                iFinish = 0
                                // get attribute info
                                string sTestComment = probeAttr_(o, "Test Comment")  // Test Comment attribute/column
                                if (sTestComment != strBlank)
                                {
                                        iLength = length(sTestComment)
                                        // process attribute
                                        while (iStart < iLength)
                                        {
                                                // check attribute
                                                sRetString = spell(o, "Test Comment", iStart, iFinish)
                                                if (sRetString != null)
                                                {
                                                        PrintModuleName()
                                        g_stOutput << strBase_ID strSpace sRetString strNewLine
                                                        // adjust accordingly
                                                        iStart = iFinish
                                                 } // end if (sRetString != null)
                                                 else
                                                        break
                                        } // end while (iStart < iLength)
                                } // end if (sTestComment != strBlank)
                        } // end if (o != null)
                }  // end for o in m do
                if (!bSingleModule)
                        close(m, false) // close the module, with NO to saving
        } // end if (bValidModule)
} //end Action()


void ProcessFolder(Folder fld)
{
        Item itm
        Module mod
        string FullModuleName
        string ModulePath
        Skip   skpItems = createString()  // used to put items alphabetically sorted
                // [1] Get items in the folder
        for itm in fld do
        {
                if (!isDeleted(itm)) put(skpItems, name(itm), itm)
        }// for itm in fld do
                // [2] process modules in the folder
        for itm in skpItems do
        {
                if (type(itm) == "Formal")
                {
                        FullModuleName = fullName(itm)
                        Action(FullModuleName)
                } // end if (type(itm) == FORMAL)
        } // end for itm in skpItems do
                // [3] recurse sub-folders and projects
        for itm in skpItems do
        {
                if (type(itm) == "Folder" or type(itm) == "Project")
                        ProcessFolder(folder(fullName(itm)))
        } // end for itm in skpItems do
        delete(skpItems)
} // ProcessFolder

string strPurpose = "User shall be able to run a script to perform spell checking on Test Comment text."
string strDialogTitle = "Test Comment Spell Check"
string strDefaultFolderPath = fullName current Folder
DB ActionBox = create(strDialogTitle,styleCentered | styleFixed)
imageCanvas = canvas(ActionBox, LOGO_WIDTH, LOGO_HEIGHT, repaint)               //puts the logo at top
string strLabelText = "This script will search for typos in the Test Comment column"
DBE dbeLabel = label(ActionBox, strLabelText)
DBE TypeRadio = radioBox(ActionBox, strSelectFileOrFolder, SFFType, 1) // Default to folder
DBE dbeDefaultFolderPath = field(ActionBox, strFolderPath,strBlank, 80,true)   //Setting to true grays out this field
//DBE dbePathLabel = label(ActionBox, strPathChangeMessage)


void Insert(DB ActionBox)
{
        fDirectory
        string sTemp
        int nType = get TypeRadio
        g_bDeleteFileValid = DeleteExistingFile(OutputFile)
        pragma runLim, 0                                           //disables the "Execution Timeout" dialog

        if (nType == 0)
        {
                bSingleModule = true
                if (g_bDeleteFileValid)
                {
                        g_stOutput = write(OutputFile)
                        Dictionary d
                        open(d, clientDictionary)
                        Action(strSpace)
                        sTemp = close(d, false)
//print "sTemp "sTemp strNewLine
                        close(g_stOutput)
                        CompleteMessage(OutputFile)
                } // end if (g_bDeleteFileValid)
        } // end if (nType == 0)
        else
        {
                bSingleModule = false
                Dictionary d
                open(d, clientDictionary)
                void DoFolder(Folder fld)
                {
                        if (g_bDeleteFileValid)
                        {
                                g_stOutput = write(OutputFile)
                                ProcessFolder(fld)
                                close(g_stOutput)
                                CompleteMessage(OutputFile)
                        } // end if (g_bDeleteFileValid)
                } DoFolder(current Folder)
                sTemp = close(d, false)
        } // end else
        if (showing ActionBox)
        {
                hide(ActionBox)
                destroy(ActionBox)  // free up resources now
        } // end if (showing ActionBox)
} // Insert
apply(ActionBox, strOk, Insert)
set(dbeDefaultFolderPath, strDefaultFolderPath) // Update into the folder path area in dialog
show ActionBox  // No text can appear after here as it will not be executed!!!!!

 

Re: Script to spell check on a column
mcnairk - Thu Sep 11 12:04:45 EDT 2014

Gedinfo - Wed Sep 10 14:53:09 EDT 2014

Stream g_stOutput
string OutputFile = "U:\\DoorsLog\\SpellCheck.txt" // Results of this script appear in this file
bool bSingleModule
bool bPrintDVP
string strModuleName
string strNewLine = "\n"
string strBlank = ""
string strSpace = " "
int LOGO_WIDTH = 400
int LOGO_HEIGHT = 95
string SFFType[] =  {"Single File", "Folder"}
string strSelectFileOrFolder = "Select Single File or Folder: "
string strFolderPath = "Folder Path:"
string BITMAP = "U:\\Temp\\file_bmp.bmp"    // This is actually located C:\Temp but the drive is mapped to U
bool g_bDeleteFileValid
string strDoorsOutput = "U:\\DoorsLog"
string strOk = "OK"


//Draws a bitmap - for canvases that displays an image
void repaint(DBE c) { bitmap(c, BITMAP, 0, 0)}


/******************************************************************************
  CompleteMessage

  Displays an Operation Complete message alerting the user where to find the resultant file
******************************************************************************/
void CompleteMessage(string strLogFile)
{
        string strMessage
        string strMap = " where U:\\ is mapped to the 'Client' drive"
        string strComplete = "Operation Complete!!! Output file can be viewed at "
        strMessage = strComplete strLogFile strMap
        infoBox strMessage
} // CompleteMessage()

bool DeleteExistingFile(string strFileToDelete)
{
    string strRetStatus = deleteFile(strFileToDelete)  // needed for 9.4
    if (strRetStatus == null)
    {
            g_bDeleteFileValid = true
    } // end if (RetStatus == null)
    else
    {
            g_bDeleteFileValid = false
            ack "Please close " strFileToDelete " then rerun this script!"
    } // end else
    return(g_bDeleteFileValid)
}  //DeleteExistingFile()


/******************************************************************************
  fDirectory()

  Create a directory if it does not exist
******************************************************************************/
void fDirectory()
{
        bool bDirExists = false
        Stat s
        s = create strDoorsOutput
        if (!null s && directory s)
                bDirExists = true
        if (bDirExists == false)
                mkdir(strDoorsOutput, strBlank)
} //fDirectory()

void PrintModuleName()
{
    if (bPrintDVP)
        {
                // Only print the module name once
                if (!bSingleModule)
                        g_stOutput << strNewLine "**************New DVP**************" strNewLine
                g_stOutput << strModuleName strNewLine
                bPrintDVP = false
        } // end if (bPrintDVP)
} // PrintModuleName()

void Action(string strFullName)
{
        bPrintDVP = true
        string strBase_ID = strBlank
        int iStart = 0
        int iFinish = 0
        int iLength = 0
        string sRetString = strBlank
        Object o
        Module m
        bool bInitial = true
        bool bValidModule = true
        bool bExecutableModule

        if (bSingleModule)
        {
                m = current
        } // end if (bSingleModule)
        else
        {
                m = read(strFullName, false)
                if (m == null)
                        bValidModule = false
        } // end else

        if (bValidModule)
        {
                strModuleName = m."Name"
                for o in m do
                {
                        // check status
                        // -----------------------------------------------------------------------
                        if (o != null)
                        {
                        strBase_ID = identifier(o)
                                iStart = 0
                                iFinish = 0
                                // get attribute info
                                string sTestComment = probeAttr_(o, "Test Comment")  // Test Comment attribute/column
                                if (sTestComment != strBlank)
                                {
                                        iLength = length(sTestComment)
                                        // process attribute
                                        while (iStart < iLength)
                                        {
                                                // check attribute
                                                sRetString = spell(o, "Test Comment", iStart, iFinish)
                                                if (sRetString != null)
                                                {
                                                        PrintModuleName()
                                        g_stOutput << strBase_ID strSpace sRetString strNewLine
                                                        // adjust accordingly
                                                        iStart = iFinish
                                                 } // end if (sRetString != null)
                                                 else
                                                        break
                                        } // end while (iStart < iLength)
                                } // end if (sTestComment != strBlank)
                        } // end if (o != null)
                }  // end for o in m do
                if (!bSingleModule)
                        close(m, false) // close the module, with NO to saving
        } // end if (bValidModule)
} //end Action()


void ProcessFolder(Folder fld)
{
        Item itm
        Module mod
        string FullModuleName
        string ModulePath
        Skip   skpItems = createString()  // used to put items alphabetically sorted
                // [1] Get items in the folder
        for itm in fld do
        {
                if (!isDeleted(itm)) put(skpItems, name(itm), itm)
        }// for itm in fld do
                // [2] process modules in the folder
        for itm in skpItems do
        {
                if (type(itm) == "Formal")
                {
                        FullModuleName = fullName(itm)
                        Action(FullModuleName)
                } // end if (type(itm) == FORMAL)
        } // end for itm in skpItems do
                // [3] recurse sub-folders and projects
        for itm in skpItems do
        {
                if (type(itm) == "Folder" or type(itm) == "Project")
                        ProcessFolder(folder(fullName(itm)))
        } // end for itm in skpItems do
        delete(skpItems)
} // ProcessFolder

string strPurpose = "User shall be able to run a script to perform spell checking on Test Comment text."
string strDialogTitle = "Test Comment Spell Check"
string strDefaultFolderPath = fullName current Folder
DB ActionBox = create(strDialogTitle,styleCentered | styleFixed)
imageCanvas = canvas(ActionBox, LOGO_WIDTH, LOGO_HEIGHT, repaint)               //puts the logo at top
string strLabelText = "This script will search for typos in the Test Comment column"
DBE dbeLabel = label(ActionBox, strLabelText)
DBE TypeRadio = radioBox(ActionBox, strSelectFileOrFolder, SFFType, 1) // Default to folder
DBE dbeDefaultFolderPath = field(ActionBox, strFolderPath,strBlank, 80,true)   //Setting to true grays out this field
//DBE dbePathLabel = label(ActionBox, strPathChangeMessage)


void Insert(DB ActionBox)
{
        fDirectory
        string sTemp
        int nType = get TypeRadio
        g_bDeleteFileValid = DeleteExistingFile(OutputFile)
        pragma runLim, 0                                           //disables the "Execution Timeout" dialog

        if (nType == 0)
        {
                bSingleModule = true
                if (g_bDeleteFileValid)
                {
                        g_stOutput = write(OutputFile)
                        Dictionary d
                        open(d, clientDictionary)
                        Action(strSpace)
                        sTemp = close(d, false)
//print "sTemp "sTemp strNewLine
                        close(g_stOutput)
                        CompleteMessage(OutputFile)
                } // end if (g_bDeleteFileValid)
        } // end if (nType == 0)
        else
        {
                bSingleModule = false
                Dictionary d
                open(d, clientDictionary)
                void DoFolder(Folder fld)
                {
                        if (g_bDeleteFileValid)
                        {
                                g_stOutput = write(OutputFile)
                                ProcessFolder(fld)
                                close(g_stOutput)
                                CompleteMessage(OutputFile)
                        } // end if (g_bDeleteFileValid)
                } DoFolder(current Folder)
                sTemp = close(d, false)
        } // end else
        if (showing ActionBox)
        {
                hide(ActionBox)
                destroy(ActionBox)  // free up resources now
        } // end if (showing ActionBox)
} // Insert
apply(ActionBox, strOk, Insert)
set(dbeDefaultFolderPath, strDefaultFolderPath) // Update into the folder path area in dialog
show ActionBox  // No text can appear after here as it will not be executed!!!!!

 

Mark,

This works well for me in DOORS 8.2 (don't ask!). My only suggestions would be:

- allow entry of the desired attribute to spell check

- display progress bar for folders with large numbers of modules (I'm checking 43)

- file/folder selector

I may work on these when I find that elusive "round to it".

Thanks,

                 Ken.